<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\UserCoupon;

class UserDrawResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $this->resource->makeHidden(['created_at', 'updated_at','reason']);
        $data = parent::toArray($request);
        if(isset($this->prize['coupon_id'])){
            $data['coupon'] = new UserCouponResource(UserCoupon::find($this->prize['coupon_id']));
        }
        return $data;
    }
}
